//
//  BK_StoreOrder_Cell.m
//  bestkeep
//
//  Created by TOPTEAM on 2017/3/31.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "BK_StoreOrder_Cell.h"
#import <Masonry.h>
#import "BK_OD_Color.h"
#define RGB(__r, __g, __b)  [UIColor colorWithRed:(1.0*(__r)/255)\
green:(1.0*(__g)/255)\
blue:(1.0*(__b)/255)\
alpha:1.0]

#define WIDTH_IMGV   24
@interface BK_StoreOrder_Cell ()

@property (nonatomic,strong) UIView * view_back;
@property (nonatomic,strong) UIImageView* ImgV_goods;    //商品图片
@property (nonatomic,strong) UILabel* lab_time_up;       //下单时间  星期
@property (nonatomic,strong) UILabel* lab_time_down;     //下单时间  日期
@property (nonatomic,strong) UILabel* lab_Money;         //商品金额
@property (nonatomic,strong) UILabel* lab_address;       //商品参数

@property (nonatomic,strong) UIView * view_line;

@end

@implementation BK_StoreOrder_Cell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        self.backgroundColor = [UIColor whiteColor];
        [self initView];
    }
    return self;
}

- (void)initView{
    
    
    /**
     * 背景View---白色
     */
    _view_back =[[UIView alloc]init];
    _view_back.backgroundColor=[UIColor whiteColor];
    [self addSubview:_view_back];
    [_view_back mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(0);
        make.left.equalTo(self.mas_left).offset(0);
        make.width.mas_equalTo(@(ScreenWidth));
        make.bottom.equalTo(self.mas_bottom);
    }];
    
    
    _lab_time_up= [UILabel new];
    _lab_time_up.textColor = kOrderLightGrey1;
    _lab_time_up.font = [UIFont systemFontOfSize:15];
    _lab_time_up.numberOfLines=1;
    _lab_time_up.text = @"加载中....";
//    _lab_time_up.text = @"周三";
    _lab_time_up.backgroundColor = [UIColor clearColor];
    [_view_back addSubview:_lab_time_up];
    [_lab_time_up mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_view_back.mas_top).offset(27/2.0);
        make.left.mas_equalTo(_view_back.mas_left).offset(ApplicationBackGauge);
        make.right.mas_equalTo(self.mas_right).offset(-30);
    }];
    
    _lab_time_down= [UILabel new];
    _lab_time_down.textColor = kOrderLightGrey1;
    _lab_time_down.font = [UIFont systemFontOfSize:14];
    _lab_time_down.numberOfLines=1;
    _lab_time_down.text = @"加载中....";
//    _lab_time_down.text = @"03-29";
    _lab_time_down.backgroundColor = [UIColor clearColor];
    [_view_back addSubview:_lab_time_down];
    [_lab_time_down mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_view_back.mas_top).offset(76/2.0);
        make.left.mas_equalTo(_view_back.mas_left).offset(ApplicationBackGauge);
        make.right.mas_equalTo(self.mas_right).offset(-30);
    }];

    
    
    
    /**
     *  订单商品图片
     */
    _ImgV_goods = [UIImageView new];
    _ImgV_goods.backgroundColor = [UIColor whiteColor];
//        _ImgV_goods.layer.borderColor = RGB(221, 221, 221).CGColor;
//        _ImgV_goods.layer.borderWidth = 0.6;
    _ImgV_goods.contentMode = UIViewContentModeScaleToFill;
    [_view_back addSubview:_ImgV_goods];
    [_ImgV_goods mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.mas_centerY);
        make.left.mas_equalTo(_view_back.mas_left).offset(ApplicationBackGauge+(73+58)/2.0);
        make.width.mas_equalTo(@(WIDTH_IMGV));
        make.height.mas_equalTo(@(WIDTH_IMGV));
    }];
    
    
    
    
    /**
     *  实付款
     */
    _lab_Money= [UILabel new];
    _lab_Money.textColor = kOrderBlack1;
    _lab_Money.font = [UIFont boldSystemFontOfSize:18];
    _lab_Money.numberOfLines=1;
    _lab_Money.text = @"加载中...";
//    _lab_Money.text = @"-¥9999.99";
    _lab_Money.textAlignment=NSTextAlignmentLeft;
    _lab_Money.backgroundColor = [UIColor clearColor];
    [_view_back addSubview:_lab_Money];
    [_lab_Money mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_view_back.mas_top).offset(20.5/2.0);
        make.left.mas_equalTo(_view_back.mas_left).offset(ApplicationBackGauge+(73+58)/2.0+24+51/2.0);
    }];
    
    

    /**
     *  店铺地址
     */
    _lab_address = [UILabel new];
    _lab_address.textColor = kOrderMediumGrey1;
    _lab_address.textAlignment=NSTextAlignmentLeft;
    _lab_address.font = [UIFont systemFontOfSize:14];
    _lab_address.numberOfLines=1;
    _lab_address.text = @"加载中....";
//    _lab_address.text = @"西安-老钢厂有糖店";
    _lab_address.backgroundColor = [UIColor clearColor];
    [_view_back addSubview:_lab_address];
    [_lab_address mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_view_back.mas_top).offset(75/2.0);
        make.left.mas_equalTo(_lab_Money.mas_left).offset(0);
    }];


    
    /**
     *  下划线
     */
    _view_line = [UILabel new];
    _view_line.backgroundColor = kOrderLineGrey2;
    [_view_back addSubview:_view_line];
    [_view_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(_view_back.mas_bottom).offset(-0.5);
        make.right.mas_equalTo(_view_back.mas_right).offset(0);
        make.left.mas_equalTo(_view_back.mas_left).offset(0);
        make.height.mas_equalTo(@(0.5));
    }];

    
}


-(void)relayOutUIWithModel:(BK_StoreOrder_Model *)model{
    
    
    /*
     * 
         //"day_name": "xxx日期名称",
         //"day_time": "xxx日期时间",
         //"pay_way": "xxx支付方式10:账户余额，20：支付宝，30：微信,支付方式",
         //"pay_amount": "xx支付金额",
         //"order_no": "xx订单号",
         //"store_address": "小店地址",
     */
    
    
    
//    _lab_time_up.text = @"周三";
    _lab_time_up.text = model.day_name;
//    _lab_time_down.text = @"03-29";
    _lab_time_down.text = model.day_time;
//    _lab_Money.text = @"-¥9999.99";
     _lab_Money.text = [NSString stringWithFormat:@"-%.2f",[[NSString stringWithFormat:@"%@",model.pay_amount] floatValue]];
//    _lab_address.text = @"西安-老钢厂有糖店";
    _lab_address.text = model.store_address;
    
    
    
    if ([[NSString stringWithFormat:@"%@",model.pay_way] integerValue]==10) {
        /*
         * 余额
         */
         _ImgV_goods.image=[UIImage imageNamed:@"BK_My_myAccount Copy"];
        
        
    }else if([[NSString stringWithFormat:@"%@",model.pay_way] integerValue]==20){
        /*
         * 支付宝
         */
        _ImgV_goods.image=[UIImage imageNamed:@"BKOrder_alipay"];
        
    }else if([[NSString stringWithFormat:@"%@",model.pay_way] integerValue]==30){
        
        /*
         * 微信
         */
        _ImgV_goods.image=[UIImage imageNamed:@"BKOrder_WeChat"];
    }
}



+(CGFloat)computeHeight:(id)data
{
    return 140.5/2.0;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
